using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using DTO;

namespace DAL
{
    public class Phieu_Deal_DAL
    {
        private SqlConnection cn = null;
        public Phieu_Deal_DAL()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Strconnection"].ConnectionString);
            cn.Open();
        }
        public void Insert(Phieu_Deal_DTO Phieu_Deal)
        {
            SqlCommand cm = new SqlCommand("Phieu_Deal_Insert", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaPhieu", Phieu_Deal.MaPhieu);
            cm.Parameters.AddWithValue("@MaMH", Phieu_Deal.MaMH);
            cm.Parameters.AddWithValue("@MaTinhTrang_Phieu", Phieu_Deal.MaTinhTrang_Phieu);
            cm.ExecuteNonQuery();
        }
        public void Update(Phieu_Deal_DTO Phieu_Deal)
        {
            SqlCommand cm = new SqlCommand("Phieu_Deal_Update", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaPhieu", Phieu_Deal.MaPhieu);
            cm.Parameters.AddWithValue("@MaMH", Phieu_Deal.MaMH);
            cm.Parameters.AddWithValue("@MaTinhTrang_Phieu", Phieu_Deal.MaTinhTrang_Phieu);
            cm.ExecuteNonQuery();
        }
        public void Delete(string iD)
        {
            SqlCommand cm = new SqlCommand("Phieu_Deal_Delete", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@MaPhieu", iD);
            cm.ExecuteNonQuery();
        }
        //public PhieuDealCollection Get(string where, int PageIndex, int PageSize,
        //    string OrderBy, string OrderDirection, out int TotalRecords)
        //{
        //    SqlCommand cm = new SqlCommand("Phieu_Deal_SET", cn);
        //    cm.CommandType = CommandType.StoredProcedure;
        //    cm.Parameters.AddWithValue("@Where", where);
        //    cm.Parameters.AddWithValue("@PageIndex", pageIndex);
        //    cm.Parameters.AddWithValue("@PageSize", pageSize);
        //    cm.Parameters.AddWithValue("@OrderBy", orderBy);
        //    cm.Parameters.AddWithValue("@OrderDirection", orderDirection);
        //    cm.Parameters.Add(new SqlParameter("@TotalRecords", DbType.Int32)).Direction = ParameterDirection.Output;

        //    SqlDataAdapter dr = cm.ExecuteReader();
        //    PhieuDealCollection PhieuDealCollection = new PhieuDealCollection();

        //    while (dr.Read())
        //    {
        //        Phieu_Deal_DTO PhieuDeal = new Phieu_Deal_DTO();
        //        PhieuDeal.MaPhieu = dr.GetValue(0).ToString();
        //        PhieuDeal.MaMH = dr.getvalue(1).ToString();
        //        PhieuDeal.MaMH = dr.GetValue(2).ToString();

        //        PhieuDealCollection.Add(PhieuDeal);

        //    }
        //    dr.Close();
        //    TotalRecords = int.Parse(cm.Parameters["@TotalRecords"].Value.ToString());
        //    return PhieuDealCollection;

        //}


        public PhieuDealCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}
